<template>
  <AuditShowPage
    labelWidth="250px"
    :formData="formData"
    :formItems="formItems"
    :handleFail="handleAuditFail"
    :handleSuccess="handleAuditSuccess"
    @goback="handleGoBack"
  >
    <h3 slot="page-header">品牌待审核-查看</h3>
    <SeriesEditor slot="seriesList" :dataSource="formData.seriesList" :tableColumns="seriesColumns" :canAdd="false" />
  </AuditShowPage>
</template>
<script>
import AuditShowPage from '@/components/AuditShowPage';
import SeriesEditor from '../components/SeriesEditor';
import { isResponseSuccess } from '@/utils/bizUtils';
import { FORM_ITEMS } from './constants';
import {
  getBrandAuditInfoService,
  auditNoPassService,
  auditPassService
} from '@/api/basics/brandManage/brandToAudit';
export default {
  components: {
    AuditShowPage,
    SeriesEditor
  },
  data () {
    return {
      formData: {},
      formItems: [...FORM_ITEMS],
      uuid: '',
      seriesColumns: [
        { title: '系列ID', key: 'seriesUuid' },
        {
          title: '系列名称',
          children: [
            { title: '原值', key: 'seriesOriginalValue' },
            { title: '现值', key: 'series' }
          ]
        },
        {
          title: '是否启用',
          children: [
            { title: '原值', key: 'seriesStateStrOriginalValue' },
            { title: '现值', key: 'seriesStateStr' }
          ]
        }
      ]
    }
  },
  mounted () {
    this.uuid = this.$route.query?.uuid
    this.getPageDetails()
  },
  methods: {
    async getPageDetails () {
      const data = { uuid: this.uuid }
      const res = await getBrandAuditInfoService(data, '.page-body')
      if (res?.retData) {
        this.formData = res.retData
      }
    },
    // 返回
    handleGoBack () {
      this.$router.push({ name: 'brandAuditList' })
    },
    // 审核不通过
    async handleAuditFail (loadingFn, messageFn, dataSource) {
      const data = { uuids: this.uuid, auditNote: dataSource?.reason }
      const res = await auditNoPassService(data, loadingFn)
      if (isResponseSuccess(res)) {
        messageFn()
        this.handleGoBack()
      }
    },
    // 审核通过
    async handleAuditSuccess (loadingFn, messageFn, dataSource) {
      const data = { uuids: this.uuid, auditNote: dataSource?.reason }
      const res = await auditPassService(data, loadingFn)
      if (isResponseSuccess(res)) {
        messageFn()
        this.handleGoBack()
      }
    },
  }
}
</script>
